package ua.com.fesvlast.hotel.tests.dao;

import static org.junit.Assert.*;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import ua.com.fesvlast.hotel.model.dao.DAOFactory;
import ua.com.fesvlast.hotel.model.enteties.Users;

public class UsersDAOTests {
	
	private Users admin;
	private Users user;
	
	@BeforeClass
	public static void beforeClass(){
		System.out.println("Before class");
	}
	
	@AfterClass
	public static void afterClass(){
		System.out.println("After class");
	}
	
	
	@Before
	public void setUpAdmin(){
		admin =new Users();
		admin.setLogin("admin");
		admin.setPassword("password");
		admin.setUserType("admin");
	}
	
	@Before
	public void setUpUser(){
		user=new Users();
		user.setLogin("user");
		user.setPassword("password");
		user.setUserType("user");
	}
	
	@After
	public void fifnishTests(){
		System.err.println("After");
	}
	
	@Test
	public void testCheckLoginAdmin(){
		assertEquals("The method expected true! Passwors is true", true, DAOFactory.getUsersDAO().checkLoginUser(admin.getLogin(), admin.getPassword()));
	}
	
	@Test
	public void testCheckLoginUserWrong(){
		user.setPassword("dfsdf");
		assertEquals("Expected false! Password is wrong", false,DAOFactory.getUsersDAO().checkLoginUser(user.getLogin(), user.getPassword()));
	}
	
	@Test
	//@Ignore
	public void testCheckLoginUserCorrect(){
		assertEquals("Expected false! Password is wrong", true,DAOFactory.getUsersDAO().checkLoginUser(user.getLogin(), user.getPassword()));
	}
	
	@Test
	public void testCheckLoginToNull(){
		user =new Users();
		assertEquals("Expected false! Password is wrong", false,DAOFactory.getUsersDAO().checkLoginUser(user.getLogin(), user.getPassword()));
	}
	
	
	@Test
	@Ignore
	public void testInsertionDataIntoDATABASE(){
		user= new Users();
		user.setLogin("John");
		user.setPassword("Pass");
		user.setUserType("user");
		
		Users userReturned=DAOFactory.getUsersDAO().createUser(user);
		assertNotNull("", userReturned);

		System.out.println(userReturned.getUserId());

	}
	
	@Test
	public void testGetListOfUsers(){
		List<Users> list =DAOFactory.getUsersDAO().getListUsers();
		assertNotNull(list);
	}
	
	@Test
	public void getUserByLoginAndPassword(){
		assertEquals("Comparing userId", 3, DAOFactory.getUsersDAO().getUser("John","Pass").getUserId());
	}

}
